package pers.qianyu.month_202102.date_20210217;

/**
 * 566. 重塑矩阵
 * https://leetcode-cn.com/problems/reshape-the-matrix/
 *
 * @author mizzle rain
 * @date 2021-02-17 15:59
 */
public class MatrixReshape {
    public int[][] matrixReshape(int[][] nums, int r, int c) {
        int h = nums.length, w = nums[0].length;
        if (h * w != r * c) return nums;
        int[][] matrix = new int[r][c];
        for (int t = 0; t < r * c; t++) {
            matrix[t / c][t % c] = nums[t / w][t % w];
        }
        return matrix;
    }
}
